#define _CRT_SECURE_NO_WARNINGS 1

#include"Stack.h"

void InitStack(Stack** s)
{
	Stack* newstack = (Stack*)malloc(sizeof(Stack));
	if (newstack == NULL)
	{
		perror("newstack malloc:");
	}
	newstack->top = -1;
	*s = newstack;
}

bool StackEmpty(Stack* s)
{
	assert(s);
	return s->top == -1;
}

bool Push(Stack* s, ElemType e)
{
	assert(s);
	if (s->top == MaxSize - 1)
	{
		return false;
	}
	s->top++;
	s->data[s->top] = e;
	return true;
}

bool Pop(Stack* s, ElemType* e)
{
	assert(s);
	if (StackEmpty(s))
	{
		return false;
	}
	*e = s->data[s->top];
	s->top--;
	return true;
}

bool GetTop(Stack* s, ElemType* e)
{
	assert(s);
	if (StackEmpty(s))
	{
		return false;
	}
	*e = s->data[s->top];
	return true;
}

void DestroyStack(Stack* s)
{
	assert(s);
	free(s);
}